import com.wei.pojo.question;
import com.wei.service.baseService;
import com.wei.service.questionService;
import com.wei.util.AMSD;
import com.wei.util.AS;
import com.wei.util.MD;
import com.wei.util.MixAMSD;
import lombok.ToString;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.script.ScriptException;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class test {
    @Test
    public void test(){
        System.out.println(123);
    }
    @Test
    public void test1(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        questionService service = (questionService) context.getBean("questionServiceImpl");
        for (question question : service.queryAllASQuestion()) {
            System.out.println(question.toString());
        }
    }
    @Test
    public void test2(){ //增添测试
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        questionService service = (questionService) context.getBean("questionServiceImpl");
        question ASquestion = new question();
        ASquestion.setContent("5+6");
        ASquestion.setResult(11);
        for (int i=0;i<10;i++){
            service.insertQuestion(ASquestion);
        }
    }
    @Test
    public void test3(){ //修改测试 连续修改50调
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        questionService service = (questionService) context.getBean("questionServiceImpl");
        question ASquestion = new question();
        ASquestion.setId(20);
        ASquestion.setContent("9+8");
        ASquestion.setResult(17);
        service.updateAsQuestion(ASquestion);
    }
    @Test
    public void test4(){
        AS as = new AS();
        System.out.println(as.calculate());
        System.out.println(as.answer());
    }
    @Test
    public void test5(){ //使用spring创建加减对象
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        AS asquestion = (AS) context.getBean("asquestion");
        System.out.println(asquestion.calculate());
        System.out.println(asquestion.answer());
    }
    @Test
    public void test6(){ //使用spring创建乘除对象
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        MD asquestion = (MD) context.getBean("mdquestion");
        System.out.println(asquestion.calculate());
        System.out.println(asquestion.answer());
    }
    @Test
    public void test7(){ //加减乘除
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        questionService service = (questionService) context.getBean("questionServiceImpl");
        AMSD asmdquestion = (AMSD) context.getBean("asmdquestion");
        question question = new question();
        question.setId(1);
        question.setContent(asmdquestion.calculate());
        question.setResult(asmdquestion.answer());
        service.updateASMDQuestion(question);
        System.out.println(question.toString());
    }
    @Test
    public void test8() throws ScriptException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        questionService service = (questionService) context.getBean("questionServiceImpl");
        MixAMSD mixquestion = (MixAMSD) context.getBean("mixquestion");
        question question = new question();
        question.setId(1);
        question.setContent(mixquestion.calculate());
        question.setResult(mixquestion.answer());
        service.updateMixQuestion(question);
    }
    @Test
    public void test9(){  //添加加减题目
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        AS asquestion = (AS) context.getBean("asquestion");
        questionService service = (questionService) context.getBean("questionServiceImpl");
        for (int i = 0; i < 24; i++) {
            question question = new question();
            question.setContent(asquestion.calculate());
            question.setResult(asquestion.answer());
            System.out.println(question.toString());
            service.insertQuestion(question);
        }
    }
    @Test
    public void test10(){  //更新加减题目
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        AS asquestion = (AS) context.getBean("asquestion");
        questionService service = (questionService) context.getBean("questionServiceImpl");
        question question = new question();
        for (int i = 1; i <=50; i++) {
            question.setId(i);
            question.setContent(asquestion.calculate());
            question.setResult(asquestion.answer());
            service.updateAsQuestion(question);
        }
    }
@Test
    public void test11(){
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    baseService service = (baseService) context.getBean("baseServiceImpl");
    List<question> list = service.Generate50AStopic();
}
    @Test
    public void test12(){
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            list.add(i);
        }
        System.out.println(list.toString());
    }
    @Test
    public void test13(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        baseService service = (baseService) context.getBean("baseServiceImpl");
        questionService service1 = (questionService) context.getBean("questionServiceImpl");
        List<question> list = service.Generate50AMSDtopic();
        for (question question : list) {
            service1.updateASMDQuestion(question);
        }
    }
    @Test
    public void test14() throws ScriptException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        baseService service = (baseService) context.getBean("baseServiceImpl");
        questionService service1 = (questionService) context.getBean("questionServiceImpl");
        List<question> list = service.Generate50Mixtopic();
        System.out.println(list.toString());
    }

}
